#include "pec.hpp"

PEC::PEC(const vector<Port*> &ports) : ports(vector<Port*>(ports)) {}

/*
 * Two PECs with the same behavior are considered as equivalent.
 * Notice they may have different BDD's.
 */

bool PEC::operator==(const PEC& other) const {
    if (this->ports.size() != other.ports.size()) return 0;
    for (int i = 0; i < this->ports.size(); i ++)
        if (this->ports[i] != other.ports[i]) return 0;
    return 1;
}

size_t PECHasher::operator()(const PEC& pec) const {
    size_t res = 17;
    for (const Port *t : pec.ports) {
        res = res * 31 + hash<string>()(t->name);
    }
    return res;
}